<template>
	<view class="goodsList">
		<view class="good-list">
			<view v-for="(item,i) in goodsList" :key="i" @click="goGoodsdateList(item)">
				<my-goods :item="item"></my-goods>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				queryObj:{
					query:'',
					pagenum:1,
					cid:'',
					pagesize:10
				},
				// 商品列表
				goodsList:[],
				// 总数
				total:'',
				// 节流阀
				isloding:false
			};
		},
		onLoad(options) {
			this.queryObj.query = options.query || ''
			this.queryObj.cid = options.cid || ''
			this.getGoodsList()
		},
		methods:{
			async getGoodsList(cd){
				this.isloding = true
				let {data:res} = await uni.$http.get('/api/public/v1/goods/search',this.queryObj)
				this.isloding = false
				cd && cd()
				if(res.meta.status !==200) return uni.$showMsg()
				console.log(res)
				this.goodsList =[...this.goodsList, ...res.message.goods]
				this.total = res.message.total
			},
			goGoodsdateList(item){
				uni.navigateTo({
					url:'/subpkg/goods_detail/goods_detail?goods_id=' + item.goods_id
				})
			}
			
		},
		// 上拉加载
		onReachBottom() {
			// 判断数据是否加载完毕
			if (this.queryObj.pagenum *this.queryObj.pagesize >= this.total) return uni.$showMsg('数据加载完毕')
			if(this.isloding) return
			this.queryObj.pagenum ++
			this.getGoodsList()
		},
		// 下拉刷新
		onPullDownRefresh() {
			this.queryObj.pagenum =1
			this.isloding = false
			this.goodsList = []
			this.total = 0
			// 刷新完关闭
			this.getGoodsList(()=>uni.stopPullDownRefresh())
		}
	}
</script>

<style lang="scss">
.goodsList{

}
</style>
